home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3146 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.3 KB  |  51 lines

  1. Path: drivel.ics.uci.edu!news
  2. From: Doug Semler <drsemler@uci.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: Template help...
  5. Date: Mon, 22 Jan 1996 06:31:25 -0800
  6. Organization: University of California, Irvine
  7. Message-ID: <31039FBD.167EB0E7@uci.edu>
  8. NNTP-Posting-Host: clownfish.ics.uci.edu
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b4 (X11; I; SunOS 4.1.4 sun4m)
  13.  
  14. Question about templating:
  15.  
  16. I have a template
  17.  
  18. template
  19. < class element >
  20. struct temp {
  21.     ...   // elements in template, ctors, etc. implementing linked list
  22. };
  23.  
  24. and define my types such:
  25.  
  26. typedef struct a_block *a;
  27. typedef <a> a_temp;
  28. typedef a_temp a_list;
  29.  
  30. typedef struct b_block *b;
  31. typedef <b> b_temp;
  32. typedef b_temp b_list;
  33.  
  34. a_list A;
  35. b_list B;
  36.  
  37. My problem is this...I want to find elements from list A based on a 
  38. character string, and list B based on an integer.  The code is the
  39. same (traverse list until found) and I would like to be able to say
  40. A->find_element(char *id);  or 
  41. B->find_element(int i);
  42.  
  43. (I have overloaded == function for char * types BTW)
  44. Is it possible?
  45.  
  46. -- 
  47. Doug Semler                      | drsemler@uci.edu
  48. University of California, Irvine | Send all flames to /dev/null
  49. Information and Computer Science | Of course these are *MY* opinions
  50. http://www.ics.uci.edu/~dsemler  | When in doubt, RTFM!
  51.